﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;

namespace Services
{
    [Export(typeof(ICSVService))]
    public class CSVService : ICSVService
    {
        public string ConstructDelimitedString<T>(IEnumerable<T> words)
        {
            if (words == null || !words.Any())
            {
                return string.Empty;
            }

            int count = words.Count();
            StringBuilder sb = new StringBuilder();

            int i = 0;

            foreach (var item in words)
            {
                sb.Append(item);

                if (i < count - 1)
                {
                    sb.Append(',');
                }

                i++;
            }

            return sb.ToString();
        }
    }
}